package com.hzhc.controller.message;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.SmsChannelService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.SmsChannelVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author dongcy
 * @date 2024/6/17 10:58
 * @description SmsChannelController
 */
@RestController
@RequestMapping("/smsChannel")
@RequiredArgsConstructor
public class SmsChannelController extends BaseController {

    private final SmsChannelService channelService;

    /**
     * 短信渠道 列表list
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/getMessageTypeList")
    public ResultUtil<List<SmsChannelVo>> getMessageTypeList(HttpServletRequest request, @RequestBody SmsChannelVo vo){
        Page<SmsChannelVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<SmsChannelVo> list = channelService.getMessageTypeList(page,vo);
        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 短信渠道 新增
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/addMessageType")
    @SysTemLog(operModul = "短信渠道-新增", operType = "ADD", operDesc = "短信渠道新增功能", modular = "PC")
    public ResultUtil<T> addMessageType(HttpServletRequest request, @RequestBody SmsChannelVo vo){
        Long userID = TokenUtil.getUserID(request);
        vo.setUserId(userID);
        return channelService.addMessageType(vo);
    }

    /**
     * 短信渠道 删除
     * @param id
     * @return
     */
    @GetMapping("/delMessageType/{id}")
    @SysTemLog(operModul = "短信渠道-删除", operType = "DELETE", operDesc = "短信渠道删除功能", modular = "PC")
    public ResultUtil<T> delMessageType(@PathVariable Long id){
        return channelService.delMessageType(id);
    }

    /**
     * 短信渠道 修改
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/updateMessageType")
    @SysTemLog(operModul = "短信渠道-修改", operType = "UPDATE", operDesc = "短信渠道修改功能", modular = "PC")
    public ResultUtil<T> updateMessageType(HttpServletRequest request,@RequestBody SmsChannelVo vo){
        Long userID = TokenUtil.getUserID(request);
        vo.setUpdateUserId(userID);
        return channelService.updateMessageType(vo);
    }




}
